home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * Simple Sample PowerTalk Application Framework
- *
- * ©1991-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * mystandardmail.c -- powertalk-specific routines
- *
- * change history:
- *
- * SJF 08/23/93 1.0f1 update to final headers, fix comments
- * SJF 04/21/93 1.0b2 update to b2
- * SJF 03/01/93 1.0b1 added digital signatures
- * SJF 02/09/93 1.0b1 update to b1
- * SJF 10/13/92 1.0d4 update to a11
- * SJF 09/09/92 1.0d3 update to a9
- * SJF 05/07/92 1.0d2 update to a6
- * SJF 11/06/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __OCE__
- #include <OCE.h>
- #endif
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
-
- #ifndef __OCEAUTHDIR__
- #include <OCEAuthDir.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- #include <string.h>
-
- #include "const.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "windowstuff.h"
- #include "draw.window.h"
- #include "draw.mailer.window.h"
- #include "utils.h"
- #include "myevents.h"
- #include "windutils.h"
- #include "strconst.h"
- #include "commands.h"
- #include "mymenus.h"
- #include "digisig.h"
-
- #include "mystandardmail.h"
-
- pascal void DrawImageProc(long refcon, Boolean inColor);
-
-
- /** HasStandardMail
- **
- ** returns true only of Standard Mail package is available and running
- **/
- Boolean HasStandardMail(void)
- {
- OSErr err;
- long response;
-
- err = Gestalt(gestaltSMPMailerVersion,&response);
- if ((err!=noErr) || (response==0))
- return false;
-
- return true;
- }
-
-
- /** InitStandardMail
- **
- ** initializes the standard mail packages by calling SMPInitMailer with the version of
- ** AOCE that we support (passing in an earlier version of AOCE than the user is running
- ** will put AOCE in that version's compatibility mode for your application, passing a later
- ** version should return an error
- **/
- OSErr InitStandardMail(void)
- {
- OSErr err;
-
- SetCursor(&gWatchCursor);
- err = SMPInitMailer(kSMPVersion);
- SetCursor(&qd.arrow);
- return err;
- }
-
-
- /** CommAddRemoveMailer
- **
- ** called when the user selects either add or remove mailer from the mail menu.
- ** this function calls either add mailer if the window has no mailer or remove mailer if it does
- **/
- void CommAddRemoveMailer(WindowPtr window)
- {
- SetCursor(&gWatchCursor); // this may take some time
-
- if (IsWindowType(window,kDrawWindow)) // we add mailers to drawing windows
- CommAddMailer(window);
- else if (IsWindowType(window,kDrawMailerWindow))
- CommRemoveMailer(window);
-
- SetCursor(&qd.arrow); // done waiting
- }
-
-
- /** CommAddMailer
- **
- ** adds a mailer to an existing window
- **/
- void CommAddMailer(WindowPtr window)
- {
- Boolean chFlag = false;
- GrafPtr savePort;
- Rect rectToInval;
-
- SendWindowMessage(window,kDeactivateMessage,&chFlag); // send the drawing a deactivate
-
- GetPort(&savePort);
- SetPort(window);
- rectToInval = window->portRect;
- rectToInval.bottom -= kScrollBarWidth;
- rectToInval.right -= kScrollBarWidth;
- EraseRect(&rectToInval);
- InvalRect(&rectToInval); // invalidate the entire window
- SetPort(savePort);
-
- MakeMailerFromDrawing(window);
- SendWindowMessage(window,kActivateMessage,&chFlag);
- }
-
-
-
- /** CommRemoveMailer
- **
- ** removes a mailer from an existing window
- **/
- void CommRemoveMailer(WindowPtr window)
- {
- Boolean chFlag = false;
- GrafPtr savePort;
- Rect rectToInval;
-
- SendWindowMessage(window,kDeactivateMessage,&chFlag);
-
- GetPort(&savePort);
- SetPort(window);
- rectToInval = window->portRect;
- rectToInval.bottom -= kScrollBarWidth;
- rectToInval.right -= kScrollBarWidth;
- EraseRect(&rectToInval);
- InvalRect(&rectToInval);
- SetPort(savePort);
-
- MakeDrawingFromMailer(window);
- SendWindowMessage(window,kActivateMessage,&chFlag);
- }
-
-
- /** CommSendLetter
- **
- ** sends a letter using SMPBeginSend/SMPEndSend
- **/
- void CommSendLetter(WindowPtr window)
- {
- char hState;
- WInfoPtr infoPtr;
- OSErr err;
- Boolean mustAddContent;
- Str255 docTitle;
- Str255 nativeFormat;
- StringPtr nativeFormatArray[1];
- OSType letterCreator;
- OSType letterType;
-
- GetResString(nativeFormat,kAppNameID,kAppName);
-
- infoPtr = BeginWindowAccess(window,&hState);
-
- GetWTitle(window,docTitle);
- nativeFormatArray[0] = (StringPtr)nativeFormat;
- SetCursor(&qd.arrow);
- err = SMPSendOptionsDialog(window,docTitle,nativeFormatArray,1,
- kSMPNativeMask|kSMPImageMask|kSMPStandardInterchangeMask,&gPreferences.sendFormat,
- nil,0L,&gPreferences.sendFormat,&gPreferences.sendOptions);
-
- if (err==userCanceledErr)
- return;
-
- if (err!=noErr) {
- DoError(err);
- return;
- }
-
- SetCursor(&gWatchCursor);
-
- // use our creator if we have native format, else use AppleMail creator
- if ((gPreferences.sendFormat.whichFormats & kSMPNativeMask)!=0) {
- letterCreator = kAppCreator;
- letterType = kCDLtrMsgType;
- }
- else {
- letterCreator = 'lap2';
- letterType = kMailLtrMsgType;
- }
- err = SMPBeginSend(window,letterCreator,letterType,&gPreferences.sendOptions,&mustAddContent);
- if (err!=noErr) {
- SetCursor(&qd.arrow);
- EndWindowAccess(window,hState);
- DoError(err);
- return;
- }
-
- if (mustAddContent) {
- if (err==noErr)
- err = AddLetterBlocks(window,infoPtr,&gPreferences.sendFormat,
- nativeFormatArray[gPreferences.sendFormat.whichNativeFormat]);
- if (err!=noErr)
- DoError(err);
- }
-
- err = SMPEndSend(window,(err==noErr));
- if (err!=noErr)
- DoError(err);
-
- EndWindowAccess(window,hState);
-
- if ((err==noErr) && gPreferences.closeOnSend)
- CommCloseWindow(window);
-
- SetCursor(&qd.arrow); // done waiting
- }
-
-
- /** LoSaveLetter
- **
- ** saves a letter using SMPBeginSave/SMPEndSave
- **/
- OSErr LoSaveLetter(WindowPtr window,WInfoPtr infoPtr,SMPSaveType saveType)
- {
- OSErr err,err2;
- FSSpec *fSpec;
- Boolean mustAddContent;
- Str255 nativeFormat;
-
- GetResString(nativeFormat,kAppNameID,kAppName);
-
- err = err2 = noErr;
-
- SetCursor(&gWatchCursor); // this may take some time
-
- fSpec = &infoPtr->fileSpec;
- err = SMPBeginSave(window,fSpec,kAppCreator,kCDLtrMsgType,saveType,&mustAddContent);
- if (err!=noErr) {
- SetCursor(&qd.arrow); // done waiting
- return err;
- }
-
- if (mustAddContent) {
- if (err==noErr)
- err2 = AddLetterBlocks(window,infoPtr,nil,nativeFormat);
- else
- err2 = noErr;
- }
-
- err = SMPEndSave(window,(err==noErr));
- if (err!=noErr)
- return err;
-
- if (err==noErr) {
- infoPtr->otherData[kLastChangedData] = 0;
- }
-
- SetCursor(&qd.arrow); // done waiting
-
- if (err==noErr)
- return err2;
- else
- return err;
- }
-
-
- /** LoSaveLetter
- **
- ** saves a letter using SMPBeginSave/SMPEndSave
- **/
- void CommReply(WindowPtr window,Boolean replyToAll)
- {
- WindowPtr replyWindow;
- Point topLeft = {0,0};
- Str255 newTitle;
- Rect newWindRect;
- Point *ptPtr;
- OSErr err;
-
- GetResString(newTitle,kDefaultFilenameID,kDefaultFilename);
- newWindRect = window->portRect;
- SetPort(window);
- ptPtr = (Point *)&newWindRect;
- LocalToGlobal(ptPtr++);
- LocalToGlobal(ptPtr);
- OffsetRect(&newWindRect,kWindowOffset,kWindowOffset);
-
- replyWindow = MakeWindow(kDrawMailerWindow,&newWindRect,newTitle,false);
- err = SMPMailerReply(window,replyWindow,replyToAll,topLeft,true,true,kDefaultIdentity,nil,0L);
- if (err!=noErr)
- DoError(err);
- ShowWindow(replyWindow);
- }
-
-
- /** CommForward
- **
- ** forwards a letter (adds an additional mailer)
- **/
- void CommForward(WindowPtr window)
- {
- WInfoPtr infoPtr;
- char hState;
-
- OSErr err;
-
- infoPtr = BeginWindowAccess(window,&hState);
-
- HandleExpand(window,infoPtr); // expand the window before doing the forward
-
- err = SMPMailerForward(window,kDefaultIdentity);
- if (err!=noErr)
- DoError(err);
-
- infoPtr->saved = false;
-
- DMailerActivateWindow(window,infoPtr,nil);
- EndWindowAccess(window,hState);
- }
-
-
- /** CommAdjacentLetter
- **
- ** opens the next available letter of our type
- **/
- void CommAdjacentLetter(void)
- {
- OSErr err,err2;
- LetterDescriptor newLetter,**oldLetter;
- OSType ltrType;
- WindowPtr window;
- WInfoPtr infoPtr;
- char hState,hState2;
- SMPMailerState state;
-
- SetCursor(&gWatchCursor);
-
- ltrType = kCDLtrMsgType;
- err = SMPGetNextLetter(<rType,1,&newLetter);
-
- for (window=MyFrontWindow(); window!=nil; window=(WindowPtr)((WindowPeek)window)->nextWindow) {
- infoPtr = BeginWindowAccess(window,&hState);
- if (IsWindowType(window,kDrawMailerWindow)) {
- err2 = SMPGetMailerState(window, &state);
- if ((err2==noErr)&&(state.hasBeenReceived)) {
- oldLetter = (LetterDescriptor **)infoPtr->otherData[kLetterDescData];
- hState2 = HGetState((Handle)oldLetter);
- HLock((Handle)oldLetter);
- if (SameLetter(*oldLetter,&newLetter))
- err = kInternalError; // don't open letter if it's already open
- HSetState((Handle)oldLetter,hState2);
- }
- }
- EndWindowAccess(window,hState);
- }
-
- if (err==noErr) {
- err = LoOpen(false,nil,&newLetter.u.mailboxSpec,true,&window);
- if (err!=noErr)
- DoError(err);
- }
- else
- SysBeep(1); // no adjacent letters
-
- SetCursor(&qd.arrow);
- }
-
-
- /** CommTagLetter
- **
- ** brings up a dialog allowing the user to tag the frontmost letter
- **/
- void CommTagLetter(void)
- {
- RString32 tag;
- OSErr err;
-
- tag.dataLength = 0;
- err = SMPTagDialog(MyFrontWindow(),&tag);
- if ((err!=noErr) && (err!=userCanceledErr))
- DoError(err);
- }
-
-
- /** ProcessPowerTalkEvent
- **
- ** used as a pre-filter for all events when a mailer window is frontmost
- **/
- OSErr ProcessPowerTalkEvent(WindowPtr window,WInfoPtr infoPtr,const EventRecord *ev,
- SMPMailerResult *mailResult)
- {
- #pragma unused (window,infoPtr)
-
- return SMPMailerEvent(ev,mailResult,nil,0L);
- }
-
-
- /** ProcessPowerTalkWhatHappened
- **
- ** take action depending on what happened when we passed an event to PowerTalk
- **/
- Boolean ProcessPowerTalkWhatHappened(WindowPtr window,WInfoPtr infoPtr,SMPMailerResult mailResult)
- {
- OSErr err;
- SMPMailerState state;
- long *lastChanged;
-
- // see if the mailer has changed
-
- err = SMPGetMailerState(window, &state);
- if (err != noErr)
- DoError(err);
-
- lastChanged = (long *) &infoPtr->otherData[kLastChangedData];
- if (*lastChanged!=state.changeCount) {
- *lastChanged = state.changeCount;
- infoPtr->changed = true;
- FixMailerMenus(window,infoPtr);
- }
-
- // track if copy window is visible
-
- if ((mailResult & kSMPCreateCopyWindowMask) != 0)
- gHasCopyWindow = true;
-
- if ((mailResult & kSMPDisposeCopyWindowMask) != 0)
- gHasCopyWindow = false;
-
- // track if the mailer has been expanded or contracted
-
- if ((mailResult & kSMPContractedMask) != 0)
- HandleContract(window,infoPtr);
-
- if ((mailResult & kSMPExpandedMask) != 0)
- HandleExpand(window,infoPtr);
-
- if (((mailResult & kSMPMailerBecomesTargetMask) != 0) ||
- ((mailResult & kSMPAppBecomesTargetMask) != 0))
- FixMailerMenus(window,infoPtr);
-
- // actually, we want to check the menus for *every* event that the mailer handles completely,
- // since we may need to change the Undo item in the File menu to keep it up to date
-
- if ((mailResult & kSMPAppShouldIgnoreEventMask) != 0)
- FixMailerMenus(window,infoPtr);
-
- if ((mailResult & kSMPAppMustHandleEventMask) != 0)
- return false; // app must handle this event
- else return true; // mailer handled this event completely
- }
-
-
- /** MakeMailerFromDrawing
- **
- ** called when a mailer is added to a drawing window
- **/
- void MakeMailerFromDrawing(WindowPtr window)
- {
- WInfoPtr infoPtr;
- char hState;
- Point topLeft = {0,0};
- OSErr err;
- short mWidth,contHeight,expHeight;
-
- SetWindowKind(window,kDrawMailerWindow);
-
- infoPtr = BeginWindowAccess(window,&hState);
-
- SetDMailerMethods(infoPtr);
- infoPtr->otherFlags[kMailerExpanded] = gPreferences.expandOnCreate;
-
- if (infoPtr->fRefNum) {
- err = FSClose(infoPtr->fRefNum);
- if (err!=noErr)
- DoError(err);
- infoPtr->fRefNum = 0;
- }
- if (infoPtr->resRefNum) {
- DSIGCopySigsToTemp(infoPtr);
- CloseResFile(infoPtr->resRefNum);
- err = ResError();
- if (err!=noErr)
- DoError(err);
- infoPtr->resRefNum = 0;
- }
-
- infoPtr->saved = false;
- infoPtr->changed = true;
-
- infoPtr->otherData[kLetterDescData] = nil;
-
- err = SMPNewMailer(window,topLeft,true,gPreferences.expandOnCreate,kDefaultIdentity,nil,0L);
- if (err!=noErr)
- DoError(err);
-
- err = SMPGetDimensions(&mWidth,&contHeight,&expHeight);
- if (err!=noErr)
- DoError(err);
- if (infoPtr->otherFlags[kMailerExpanded])
- infoPtr->topIndent = expHeight;
- else
- infoPtr->topIndent = contHeight;
-
- MoveScrollBars(window);
-
- EndWindowAccess(window,hState);
- }
-
-
- /** MakeDrawingFromMailer
- **
- ** called when a mailer is removed from a letter window (turning it into a drawing only)
- **/
- void MakeDrawingFromMailer(WindowPtr window)
- {
- WInfoPtr infoPtr;
- char hState;
-
- OSErr err;
-
- if (!CanCloseLetter(window)) // make sure no open enclosures
- return;
-
- err = SMPDisposeMailer(window,&gPreferences.closeOptions);
- if (err!=noErr)
- DoError(err);
-
- SetWindowKind(window,kDrawWindow);
-
- infoPtr = BeginWindowAccess(window,&hState);
-
- infoPtr->topIndent = 0;
- if (!CheckPageSize(window,infoPtr)) // draw area may have gotten too big for us
- MoveScrollBars(window);
-
- if (infoPtr->fRefNum) {
- err = FSClose(infoPtr->fRefNum);
- if (err!=noErr)
- DoError(err);
- infoPtr->fRefNum = 0;
- }
- if (infoPtr->resRefNum) {
- DSIGCopySigsToTemp(infoPtr);
- CloseResFile(infoPtr->resRefNum);
- err = ResError();
- if (err!=noErr)
- DoError(err);
- infoPtr->resRefNum = 0;
- }
-
- infoPtr->saved = false;
- infoPtr->changed = true;
-
- if (infoPtr->otherData[kLetterDescData])
- DisposHandleChk((Handle)infoPtr->otherData[kLetterDescData]);
-
- SetDrawMethods(infoPtr);
-
- EndWindowAccess(window,hState);
- }
-
-
- /** FixMailerMenus
- **
- ** fixes up the all of the menus associated with mailer windows
- **/
- void FixMailerMenus(WindowPtr window,WInfoPtr infoPtr)
- {
- #pragma unused (infoPtr)
- MenuHandle theMenu;
- Str255 removeMailerText;
- OSErr err;
- SMPMailerState state;
- Boolean undoEnabled;
-
- // get mailer's state so we can set the menus
-
- err = SMPGetMailerState(window, &state);
- if (err != noErr)
- DoError(err);
-
- // edit menu
-
- theMenu = GetMHandle(kEditMenu);
- EnableAllMenuItems(theMenu);
- if (state.isTarget) {
- if (!state.canCut)
- DisableItem(theMenu, kCutItem);
- if (!state.canCopy)
- DisableItem(theMenu, kCopyItem);
- if (!state.canPaste)
- DisableItem(theMenu, kPasteItem);
- if (!state.canClear)
- DisableItem(theMenu, kClearItem);
- if (!state.canSelectAll)
- DisableItem(theMenu, kSelectAllItem);
- }
- else
- FixDrawEditMenu();
-
- // fix undo item
-
- switch (state.undoState) {
- case kSMPMailerUndo:
- SetItem(theMenu,kUndoItem,state.undoWhat);
- EnableItem(theMenu,kUndoItem);
- ClearAppUndo();
- undoEnabled = true;
- break;
- case kSMPUndoDisabled:
- ClearAppUndo();
- undoEnabled = SetupAppUndo();
- break;
- case kSMPAppMayUndo:
- undoEnabled = SetupAppUndo();
- break;
- }
-
- if (state.isTarget && !state.canCut && !state.canCopy && !state.canPaste && !state.canClear &&
- !state.canSelectAll && !undoEnabled)
- DisableItem(theMenu,0); // disable edit menu title
-
- // mail menu
-
- theMenu = GetMHandle(kMailMenu);
- EnableAllMenuItems(theMenu);
- GetResString(removeMailerText,kRemoveMailerTextID,kRemoveMailerText);
- SetItem(theMenu,kAddRemMailItem,removeMailerText);
-
- if (state.hasBeenReceived)
- DisableItem(theMenu, kSendItem); // disable send when letter has been received
- else
- DisableItem(theMenu, kForwardItem); // disable forward when letter has not been received
-
- // disable reply if letter has not been received **and** we didn't just forward it
-
- if (!state.hasBeenReceived && (state.mailerCount==1)) {
- DisableItem(theMenu, kReplyItem);
- DisableItem(theMenu, kReplyToAllItem);
- }
-
- // disable tag if the canTag field is false
-
- if (!state.canTag)
- DisableItem(theMenu, kTagLetterItem);
-
- gMenusDirty = true;
- }
-
-
- /** DrawImageProc
- **
- ** callback for snapshot image blocks to draw shapes into the snapshot block for a page
- **/
- pascal void DrawImageProc(long refCon, Boolean inColor)
- {
- #pragma unused (inColor)
- OpenCPicParams newHeader;
- OSErr err;
- Point zeroPt = {0,0};
- WInfoPtr infoPtr;
- TPrInfo prInfo;
-
- infoPtr = (WInfoPtr)refCon;
- prInfo = (**(infoPtr->printRecord)).prInfo;
-
- newHeader.srcRect = prInfo.rPage;
- newHeader.hRes = FixRatio(prInfo.iHRes,1);
- newHeader.vRes = FixRatio(prInfo.iVRes,1);
- newHeader.version = -2;
- newHeader.reserved1 = 0;
- newHeader.reserved2 = 0L;
-
- err = SMPNewPage(&newHeader);
- if (err!=noErr)
- DoError(err);
-
- DrawAllShapes(infoPtr,zeroPt);
- }
-
-
- /** DrawImageToPicture
- **
- ** called to draw the shapes on a page into a Picture for standard interchange (AppleMail) format
- **/
- PicHandle DrawImageToPicture(WindowPtr window,WInfoPtr infoPtr)
- {
- PicHandle thePicture;
- RgnHandle saveRgn;
- GrafPtr savePort;
- Point zeroPt = {0,0};
- TPrInfo prInfo;
-
- prInfo = (**(infoPtr->printRecord)).prInfo;
-
- GetPort(&savePort);
- SetPort(window);
- saveRgn = NewRgn();
- GetClip(saveRgn);
- ClipRect(&prInfo.rPage);
- thePicture = OpenPicture(&prInfo.rPage);
- DrawAllShapes(infoPtr,zeroPt);
- ClosePicture();
- SetClip(saveRgn);
- DisposeRgn(saveRgn);
- SetPort(savePort);
-
- return thePicture;
- }
-
-
- /*------------------------------------------------------------------------------------------*/
- /* functions not called outside of this file */
- /*------------------------------------------------------------------------------------------*/
-
-
- /** AddLetterBlocks
- **
- ** adds snapshot, applemail, and native format blocks to a letter being sent/saved
- **/
- OSErr AddLetterBlocks(WindowPtr window,WInfoPtr infoPtr,SMPSendFormat *sendFormat,
- StringPtr nativeFormatName)
- {
- OSErr err = noErr;
-
- // add image (snapshot)
-
- if (!sendFormat || (sendFormat->whichFormats&kSMPImageMask)) {
- err = AddLetterImage(window,infoPtr);
- if (err!=noErr)
- return err;
- }
-
- // add standard letter interchange format (AppleMail)
-
- if (!sendFormat || (sendFormat->whichFormats&kSMPStandardInterchangeMask)) {
- err = AddAppleMailContent(window,infoPtr);
- if (err!=noErr)
- return err;
- }
-
- // add main content enclosure (native)
-
- if (!sendFormat || (sendFormat->whichFormats&kSMPNativeMask)) {
- err = AddNativeContent(window,infoPtr,nativeFormatName);
- if (err!=noErr)
- return err;
- }
-
- return err;
- }
-
-
- /** AddNativeContent
- **
- ** adds the native format block to a letter by saving the document to a temporary file
- **/
- OSErr AddNativeContent(WindowPtr window,WInfoPtr infoPtr,StringPtr nativeFormatName)
- {
- OSErr err;
- FSSpec fSpec;
- OCECreatorType blockType;
-
- // save file temporarily so we can add by FSSpec
-
- err = SaveFileToTemp(infoPtr,&fSpec);
- if (err!=noErr)
- return err;
- err = SMPAddMainEnclosure(window,&fSpec);
- FSpDelete(&fSpec);
-
- // add native format name string block
-
- if (err==noErr) {
- blockType.msgCreator = kMailAppleMailCreator;
- blockType.msgType = kSMPNativeFormatName;
- err = SMPAddBlock(window,&blockType,false,&nativeFormatName[1],nativeFormatName[0],
- kMailFromStart,0);
- }
-
- return err;
- }
-
-
- /** AddAppleMailContent
- **
- ** adds the standard interchange applemail content to a letter by imaging page to a picture
- **/
- OSErr AddAppleMailContent(WindowPtr window,WInfoPtr infoPtr)
- {
- OSErr err;
- PicHandle thePicture;
-
- thePicture = DrawImageToPicture(window,infoPtr);
- if (thePicture) {
- HLock((Handle)thePicture);
- err = SMPAddContent(window,kMailPictSegmentType,false,*thePicture,
- GetHandleSize((Handle)thePicture),nil,true,smRoman);
- KillPicture(thePicture);
- }
- else return kInternalError;
-
- return err;
- }
-
-
- /** AddLetterImage
- **
- ** adds the snapshot format to a letter by using the SMPImage call which calls my DrawImageProc
- **/
- OSErr AddLetterImage(WindowPtr window,WInfoPtr infoPtr)
- {
- return SMPImage(window,DrawImageProc,(long)infoPtr,false);
- }
-
-
- /** HandleExpand
- **
- ** handles the case when the user expands the mailer to full size
- **/
- void HandleExpand(WindowPtr window,WInfoPtr infoPtr)
- {
- OSErr err;
- Rect rectToInval;
- GrafPtr savePort;
- short expHeight,contHeight,mWidth;
-
- err = SMPGetDimensions(&mWidth,&contHeight,&expHeight);
- if (err!=noErr)
- DoError(err);
-
- infoPtr->otherFlags[kMailerExpanded] = true;
- infoPtr->topIndent = expHeight;
-
- rectToInval = window->portRect;
- rectToInval.top += expHeight;
- rectToInval.bottom -= kScrollBarWidth;
- rectToInval.right -= kScrollBarWidth;
-
- GetPort(&savePort);
- SetPort(window);
- InvalRect(&rectToInval);
-
- MoveScrollBars(window);
-
- err = SMPExpandOrContract(window, true);
- // ignore errors- we may already be expanded
-
- SetPort(savePort);
- }
-
-
- /** HandleContract
- **
- ** handles the case when the user contracts the mailer to a single line
- **/
- void HandleContract(WindowPtr window,WInfoPtr infoPtr)
- {
- OSErr err;
- Rect rectToInval;
- GrafPtr savePort;
- short expHeight,contHeight,mWidth;
-
- err = SMPGetDimensions(&mWidth,&contHeight,&expHeight);
- if (err!=noErr)
- DoError(err);
-
- infoPtr->otherFlags[kMailerExpanded] = false;
- infoPtr->topIndent = contHeight;
-
- rectToInval = window->portRect;
- rectToInval.top += contHeight;
- rectToInval.bottom -= kScrollBarWidth;
- rectToInval.right -= kScrollBarWidth;
-
- GetPort(&savePort);
- SetPort(window);
- InvalRect(&rectToInval);
-
- if (!CheckPageSize(window,infoPtr)) // draw area may have gotten too big for us
- MoveScrollBars(window);
-
- // note that we don't call ExpandOrContract() to contract mailer- it's done by mail package
-
- SetPort(savePort);
- }
-
-
- /** CanCloseLetter
- **
- ** returns true if the given letter can be closed without problems.
- ** also, displays the close options dialog if the user so wishes
- **/
- Boolean CanCloseLetter(WindowPtr window)
- {
- OSErr err;
- WInfoPtr infoPtr;
- char hState;
- Boolean returnValue;
-
- returnValue = true;
- infoPtr = BeginWindowAccess(window,&hState);
-
- if (IsWindowType(window,kDrawMailerWindow)) {
-
- // display close options dialog
-
- if (gPreferences.closeOptionsDialog) {
- SetCursor(&qd.arrow);
- err = SMPCloseOptionsDialog(window,&gPreferences.closeOptions);
- if (err!=noErr)
- returnValue = false;
- }
-
- if (returnValue==true) {
-
- // close main enclosure (if we're a received letter)
-
- if (infoPtr->fRefNum) {
- err = FSClose(infoPtr->fRefNum);
- if (err!=noErr)
- DoError(err);
- infoPtr->fRefNum = 0;
- }
- if (infoPtr->resRefNum) {
- CloseResFile(infoPtr->resRefNum);
- err = ResError();
- if (err!=noErr)
- DoError(err);
- infoPtr->resRefNum = 0;
- }
-
- // see if we can close the letter now
-
- err = SMPPrepareToClose(window);
- if (err==kSMPHasOpenAttachments) {
- SetCursor(&qd.arrow);
- StopAlert(kHasOpenAttachID,nil);
- returnValue = false;
- }
- else if (err==kSMPCopyInProgress) {
- SetCursor(&qd.arrow);
- StopAlert(kCopyInProgress,nil);
- returnValue = false;
- }
- }
- }
-
- EndWindowAccess(window,hState);
- return returnValue;
- }
-
-
- /** SameLetter
- **
- ** returns true if the two letterdescriptors passed in are for the same letter
- ** (used for getting the adjacent letter)
- **/
- Boolean SameLetter(const LetterDescriptor *one,const LetterDescriptor *two)
- {
- if (one->onDisk != two->onDisk)
- return false;
-
- if (one->onDisk) {
-
- // compare fsspecs
-
- return ((one->u.fileSpec.vRefNum == two->u.fileSpec.vRefNum) &&
- (one->u.fileSpec.parID == two->u.fileSpec.parID) &&
- EqualString(one->u.fileSpec.name,two->u.fileSpec.name,false,true));
- }
- else {
-
- // compare letterspecs
-
- return ((one->u.mailboxSpec.spec[0] == two->u.mailboxSpec.spec[0]) &&
- (one->u.mailboxSpec.spec[1] == two->u.mailboxSpec.spec[1]) &&
- (one->u.mailboxSpec.spec[2] == two->u.mailboxSpec.spec[2]));
- }
- }